package com.cyjt.operation.adapter;

import java.util.List;

import com.cyjt.operation.R;
import com.cyjt.operation.bean.BaseStationInfo;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 基站列表的Adapter
 * 
 * @author wsw
 * 
 */
public class BaseStationListAdapter extends BaseAdapter {
	private Activity activity;
	private List<BaseStationInfo> baseStationInfolists;

	public BaseStationListAdapter(Activity context, List<BaseStationInfo> baseStationInfolists) {
		this.activity = context;
		this.baseStationInfolists = baseStationInfolists;
	}

	@Override
	public int getCount() {
		return baseStationInfolists.size();
	}

	@Override
	public Object getItem(int position) {
		return baseStationInfolists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public class ViewHolder {
		private TextView textView_item_for_baseStation_code, textView_item_for_baseStation_lastDate,
				textView_item_for_baseStation_status;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(activity);
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.list_view_item_for_basestation_status, null);
			viewHolder = new ViewHolder();
			viewHolder.textView_item_for_baseStation_code = (TextView) convertView
					.findViewById(R.id.textView_item_for_baseStation_code);
			viewHolder.textView_item_for_baseStation_lastDate = (TextView) convertView
					.findViewById(R.id.textView_item_for_baseStation_lastDate);
			viewHolder.textView_item_for_baseStation_status = (TextView) convertView
					.findViewById(R.id.textView_item_for_baseStation_status);
			convertView.setTag(viewHolder);
		} else
			viewHolder = (ViewHolder) convertView.getTag();
		BaseStationInfo baseStationInfo = baseStationInfolists.get(position);
		viewHolder.textView_item_for_baseStation_code.setText(baseStationInfo.getCode() + "");
		viewHolder.textView_item_for_baseStation_lastDate.setText(baseStationInfo.getLastAtString() + "");
		viewHolder.textView_item_for_baseStation_status.setText(baseStationInfo.getStatusToString());
		return convertView;
	}

}
